package root.electronclass.electronclass.personal.fragment.attendance

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.core.text.bold
import androidx.core.text.buildSpannedString
import androidx.core.view.updateLayoutParams
import root.electronclass.electronclass.adapter.GridSpacingItemDecoration
import root.electronclass.electronclass.common.base.BasicAdapter
import root.electronclass.electronclass.common.base.BasicDialogFragment
import root.electronclass.electronclass.common.base.ViewBindingFragment.Companion.EXTRA_DATA
import root.electronclass.electronclass.databinding.FragmentPersonalAttendanceDetailDialogBinding
import root.electronclass.electronclass.databinding.FragmentPersonalAttendanceDetailDialogItemBinding
import root.electronclass.electronclass.grade.model.AttendanceInfo
import root.electronclass.electronclass.mvp.GlobalParameter

/**
 * 考勤详情
 * @author Lokiy
 * @date 2023/3/24 22:30
 */
class PersonalAttendanceDetailDialog : BasicDialogFragment<FragmentPersonalAttendanceDetailDialogBinding>() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        val info: AttendanceInfo = arguments?.getParcelable(EXTRA_DATA) ?: return
        parentBinding.dialogLayout.updateLayoutParams<ViewGroup.LayoutParams> {
            width = 952
        }
        binding.name.text = buildSpannedString {
            bold { append("姓　名：") }
            append(info.name ?: "")
        }
        binding.no.text = buildSpannedString {
            bold { append("学　号：") }
            append(GlobalParameter.getSTUDENT()?.userNo ?: "")
        }
        binding.className.text = buildSpannedString {
            bold { append("班　级：") }
            append(GlobalParameter.getEcardInfo().className ?: "")
        }
        binding.school.text = buildSpannedString {
            bold { append("学　校：") }
            append(GlobalParameter.getSchoolInfo()?.schoolName ?: "")
        }
        binding.temperature.text = buildSpannedString {
            bold { append("体　温：") }
            append(info.temperature?.let { "$it℃" } ?: "")
        }
        binding.location.text = buildSpannedString {
            bold { append("考勤点：") }
            append(info.doorName ?: "")
        }
        val adapter = BasicAdapter<String, FragmentPersonalAttendanceDetailDialogItemBinding> { holder, item ->
            holder.binding.itemImage.setImageURI(item)
        }
        adapter.refresh(info.urls.toList())
        binding.recycler.addItemDecoration(GridSpacingItemDecoration(6, 24, false))
        binding.recycler.adapter = adapter
    }
}